checkbox kullanımı
17.05.2016 - 05:51
Merhabalar
Checkbox kutularının hepsini isaretlemeden program kayit yapmiyor.Yani hepsini isaretleyip kayit ettikten sonra tek isaretleyip kayit yapabiliyorum.Hatami bulabiilirmisiniz?
package com.ugurkrky.uygulama; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.Toast; import com.android.volley.AuthFailureError; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.Volley; import java.util.HashMap; import java.util.Map; public class mesajkaydet extends AppCompatActivity { Button mesajkayit; EditText mesaj; RequestQueue requestQueue; String insertUrl = ("http://10.0.3.2/msosyal/mesajkayit.php"); String sonuc1,sonuc2,sonuc3,sonuc4; CheckBox cb1,cb1i,cb2,cb2i; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mesajkaydet); cb1=(CheckBox)findViewById(R.id.bir); cb1i=(CheckBox)findViewById(R.id.birio); cb2=(CheckBox)findViewById(R.id.iki); cb2i=(CheckBox)findViewById(R.id.ikiio); cb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(cb1.isChecked()) { sonuc1="1";} } }); cb1i.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(cb1i.isChecked()) { sonuc2="2";} } }); cb2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(cb2.isChecked()) { sonuc3="3";} } }); cb2i.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(cb2i.isChecked()) {sonuc4="4";} } }); mesaj=(EditText)findViewById(R.id.mesajalan); mesajkayit=(Button) findViewById(R.id.mesajgonder); requestQueue = Volley.newRequestQueue(getApplicationContext()); assert mesajkayit != null; mesajkayit.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { StringRequest request = new StringRequest(Request.Method.POST, insertUrl, new Response.Listener<String>() { @Override public void onResponse(String response) { Toast.makeText(getApplicationContext(), "Gönderildi", Toast.LENGTH_SHORT).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(getApplicationContext(), "Bağlantı hatası", Toast.LENGTH_SHORT).show(); } }) { @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String,String> parameters = new HashMap<String, String>(); parameters.put("mesaj",mesaj.getText().toString()); parameters.put("cb1", sonuc1); parameters.put("cb1i", sonuc2); parameters.put("cb2", sonuc3); parameters.put("cb2i",sonuc4.toString()); return parameters; } }; requestQueue.add(request); } }); } }
334
Görüntülenme
0 Beğeni